package com.netty.admin.controller;

import ch.qos.logback.core.pattern.util.RestrictedEscapeUtil;
import com.netty.admin.security.service.LoginService;
import com.netty.admin.service.AuthService;
import com.netty.common.annotation.Log;
import com.netty.common.entity.bo.AuthUser;
import com.netty.common.entity.result.Result;
import com.netty.common.enums.BusinessType;
import com.netty.common.enums.OperatorType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiuXiaoYu
 * @date 2022/2/1- 16:08
 */
@RestController
public class AuthController {
    @Autowired
    private LoginService loginService;

    /**
     * 用户登录
     *
     * @param authUser
     * @return
     */
    @PostMapping("/auth/login")
    @Log(title = "登录", businessType = BusinessType.LOGIN, operatorType = OperatorType.USER)
    public Result<?> login(@RequestBody @Validated AuthUser authUser) {
        String token = loginService.login(authUser.getUsername(), authUser.getPassword());
        return Result.success(token);
    }

}
